<template>
  <div class="adminLogin">
    <div class="form-container">
      <!-- 登陆 -->
      <el-form :model="model" :rules="loginRules" label-width="60px">
        <el-form-item prop="account">
          <el-input
            v-model="model.account"
            type="text"
            placeholder="请输入用户名"
          />
        </el-form-item>
        <el-form-item prop="account">
          <el-input
            v-model="model.password"
            type="password"
            placeholder="请输入密码"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="mini" @click="handelLogin"
            >登陆</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!-- 侧边栏内容 -->
    <div class="overlay-container">
      <div class="overlay-panel">
        <p>因为有悔，所以披星戴月；</p>
        <p>因为有梦，所以奋不顾身。</p>
      </div>
    </div>
  </div>
</template>

<script>
import { Login } from "@/api/index.js";
export default {
  name: "adminlogin",
  data() {
    return {
      model: {},
      loginRules: {},
    };
  },
  methods: {
    // 登录
    handelLogin() {
      if (!this.model.username && !this.model.password) {
        this.$message.error("请填写完整的信息!");
      } else {
        Login(this.model)
          .then((res) => {
            if (res.data.status == 401) {
              this.$message.info(res.data.msg);
            } else {
              localStorage.token = res.data.token;
              localStorage.user = JSON.stringify(res.data.data);
              if (res.data.data.type == "2") {
                this.$message.success(
                  `欢迎 ${res.data.data.account}, 今天也要加油鸭！ `
                );
                this.$router.push("/wellcome");
              } else {
                const h = this.$createElement;
                this.$notify({
                  title: "提示",
                  message: h(
                    "i",
                    { style: "color: teal" },
                    `非常抱歉！ ${res.data.data.account}, 您没有管理权限，无法登录。`
                  ),
                });
              }
            }
          })
          .catch((err) => {
            if (err) {
              this.$message.error("登录失败！");
            }
          });
      }
    },
  },
};
</script>
<style lang="scss" scope>
.adminLogin {
  height: 100vh;
  display: flex;
  overflow: hidden;
  .form-container {
    flex: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    background: #e1e1e1;
    .el-input__inner {
      border: 1px solid #e3e3e3;
      background: #e3e3e3;
    }
  }
  .overlay-container {
    flex: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: #b8d6c2;
    .overlay-panel {
      p {
        font-size: 22px;
        font-weight: bold;
      }
    }
  }
}
</style>
